/**
 * 敌人飞机管理类
 */
var BaseNode = require('./../../../FrameWork/Component/BaseNode');
var _ = require('./../../../FrameWork/we_underscore');
var UtilGameObject = require('./../../../FrameWork/Utils/UtilGameObject');
cc.Class(
{
    extends: BaseNode,

    properties:
    {
        nodeParentEnemy:
        {
            default: null,
            type: cc.Node,
            displayName: '敌机父节点'
        },

        prefabEnemyPlane:
        {
            default: null,
            type: cc.Prefab,
            displayName: '敌机预设'
        },

        sendRateRandom:
        {
            default: cc.Vec2.ZERO,
            displayName: '随机发射频率[毫秒]'
        },

        isOnLoad:
        {
            default: false,
            displayName: '启动自动开始动作'
        },
        isLoop:
        {
            default: true,
            displayName: '无限循环'
        }
    },
    onLoad()
    {
        if (this.isOnLoad)
        {
            this.doSend();
        }
    },

    doSend()
    {
        var sendRate = _.random(this.sendRateRandom.x, this.sendRateRandom.y);
        var actArray = [
            cc.delayTime(sendRate * 0.001),
            cc.callFunc(function()
            {
                this.node.stopAction();
                UtilGameObject.getCtrByPrefabs(this.prefabEnemyPlane, this.nodeParentEnemy);
                if (this.isLoop)
                {
                    this.doSend();
                }

            }.bind(this))
        ];
        var seq = cc.sequence(actArray);

        this.node.runAction(seq);
    }
});
